import numpy as np

def loadDataSet(fileName):
    numFeat = len(open(fileName).readline().split(','))-1
    dataMat=[];labelMat = []
    fr = open(fileName)
    for line in fr.readlines():
        lineArr = []
        print(line)
        curLine = line.strip().split(',')
        for i in range(numFeat):
            lineArr.append(float(curLine[i]))
        dataMat.append(lineArr)
        labelMat.append(float(curLine[-1]))
    return dataMat, labelMat

# 回归方程求取函数
def fit(x,y):
    if len(x) != len(y):
        return
    numerator = 0.0
    denominator = 0.0
    x_mean = np.mean(x)
    y_mean = np.mean(y)
    for i in range(len(x)):
        numerator += (x[i]-x_mean)*(y[i]-y_mean)
        denominator += np.square((x[i]-x_mean))
    print('numerator:',numerator,'denominator:',denominator)
    b0 = numerator/denominator
    b1 = y_mean - b0*x_mean
    return b0,b1


# 定义预测函数
def predit(x,b0,b1):
    return b0*x + b1    